<template>
	<view class="container">
		<view class="diygw-col-24">
			<view class="diygw-search">
				<view class="flex1 flex padding-xs solid radius">
					<text style="color: #555 !important" class="diy-icon-search"></text>
					<input class="flex1" name="search" type="" v-model="search" placeholder="请输入关键字" />
				</view>
				<view @tap="navigateTo" data-type="page" data-url="/pages/youxuanxiangmu/youxuanxiangmuliebiao" style="color: #333 !important" class="diygw-tag margin-left-xs radius-xs"> 搜索 </view>
			</view>
		</view>
		<view class="flex diygw-col-24">
			<swiper class="swiper" indicator-color="rgba(51, 51, 51, 0.39)" indicator-active-color="#fff" indicator-dots="true" autoplay interval="3000" circular="true" style="height: 150px">
				<swiper-item v-for="(item, index) in firstImage.data.list" :key="index" class="diygw-swiper-item">
					<view class="diygw-swiper-item-wrap">
						<image :src="item.url_" class="diygw-swiper-image"></image>   
						<view class="diygw-swiper-item-title">
							{{ item.name_ }}
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="flex diygw-col-24 justify-between flex-nowrap flex1-clz">
			<view class="flex diygw-dropdown diygw-col-0 dropdowns-clz">
				<diy-dropdown class="flex-sub" direction="down" close-on-click-overlay="false" ref="refDropdowns">
					<diy-dropdown-item @change="changeDropdowns0" v-model="dropdowns0" title="评论" :options="dropdownsDatas0"></diy-dropdown-item>
					<diy-dropdown-item @change="changeDropdowns1" v-model="dropdowns1" title="最新" :options="dropdownsDatas1"></diy-dropdown-item>
					<diy-dropdown-item @change="changeDropdowns2" v-model="dropdowns2" title="离我最近" :options="dropdownsDatas2"></diy-dropdown-item>
				</diy-dropdown>
			</view>
			<view class="flex flex-wrap diygw-col-0 justify-end flex2-clz">
				<view class="diygw-col-0 text1-clz"> 更多项目 </view>
				<view class="flex diygw-col-0 avatar1-clz">
					<view @tap="navigateTo" data-type="page" data-url="/pages/youxuanxiangmu/youxuanxiangmuliebiao" class="diygw-avatar xs orange radius">
						<text class="diy-icon-roundright"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="flex diygw-col-24 diygw-bottom">
			<view class="diygw-grid diygw-actions">
				<button @tap="navigateTo" data-type="page" data-url="/pages/index/shouye" class="diygw-action addon">
					<view class="diygw-grid-inner">
						<view class="diygw-grid-icon diygw-avatar diy-icon-homefill" style="color: rgba(167, 160, 165, 0.97)"> </view>
						<view class="diygw-grid-title"> 首页 </view>
					</view>
				</button>
				<button class="diygw-action addon">
					<view class="diygw-grid-inner">
						<view class="diygw-grid-icon diygw-avatar diy-icon-message"> </view>
						<view class="diygw-grid-title"> 消息中心 </view>
					</view>
				</button>
				<button @tap="navigateTo" data-type="page" data-url="/pages/youxuanxiangmu/youxuanxiangmu" class="diygw-action addon">
					<view class="diygw-grid-inner">
						<view class="diygw-grid-icon diygw-avatar diy-icon-crownfill" style="color: #f10a0a"> </view>
						<view class="diygw-grid-title"> 优选项目 </view>
					</view>
				</button>
				<button @tap="navigateTo" data-type="page" data-url="/pages/my/qiyejiagerenzhongxin" class="diygw-action addon">
					<view class="diygw-grid-inner">
						<view class="diygw-grid-icon diygw-avatar diy-icon-my"> </view>
						<view class="diygw-grid-title"> 我的 </view>
					</view>
				</button>
			</view>
		</view>
		<view v-for="(item, index) in project.data.list" :key="index" class="flex diygw-col-24 justify-around flex-nowrap flex5-clz" @tap="navigateTo" data-type="page" data-url="/pages/youxuanxiangmu/xiangmuxiangqing" :data-id="item.id_">
			<view class="flex diygw-col-0 justify-center">
				<view v-for="(item, index) in project.data.list" :key="index" class="diygw-avatar xs radius bg-none">
					<image mode="aspectFit" class="diygw-avatar-img radius" :src="item.picture_"></image>
				</view>
			</view>
			<view class="flex diygw-col-24 flex-direction-column justify-start flex-wrap flex8-clz">
				<view class="flex flex-wrap diygw-col-0 flex10-clz">
					<view class="diygw-col-0 text2-clz">
						{{ item.project_name_ }}
					</view>
					<view class="diygw-col-0">
						{{ item.project_type_ }}
					</view>
				</view>
				<view class="flex flex-wrap diygw-col-0 flex12-clz">
					<view class="diygw-col-0 text6-clz">
						{{ item.need_type_ }}
					</view>
					<view class="diygw-col-0">
						{{ item.type_value_ }}
					</view>
				</view>
				<view class="flex flex-wrap diygw-col-0 flex15-clz">
					<view class="diygw-col-0 text12-clz">
						{{ item.need_detail_ }}
					</view>
					<view class="diygw-col-0">
						{{ item.detail_value_ }}
					</view>
				</view>
			</view>
			<view class="flex diygw-col-0 justify-end items-end flex-nowrap flex18-clz">
				<view class="flex diygw-col-0 justify-end avatar4-clz">
					<view class="diygw-avatar xs radius">
						<text class="diy-icon-commentfill"></text>
					</view>
				</view>
				<view class="diygw-col-0 text21-clz"> 256 </view>
			</view>
		</view>
		<view class="clearfix"></view>
	</view>
</template>

<script>
	//create by: 邓志锋 <280160522@qq.com> <https://www.diygw.com> DIYGW可视化设计一键生成源码
	export default {
		data() {
			return {
				//用户全局信息
				userInfo: {},
				project: {
					code: '200',
					data: {
						count: 7,
						list: [
							{
								project_type_: '教育业',
								user_phone_: '123',
								project_id_: '434440356570595329',
								user_name_: '用户1',
								detail_value_: '500',
								id_: '434440356570595329',
								type_value_: '5%股份',
								project_status: '优选发布',
								need_detail_: '椅子',
								project_name_: '作业帮',
								user_id_: '434443664980705281',
								project_paper_: '',
								need_type_: '人才',
								picture_: 'image1',
								project_desc_: '好项目'
							},
							{
								project_type_: '食品业',
								user_phone_: '123',
								project_id_: '434554158620868609',
								user_name_: '用户2',
								detail_value_: '500',
								id_: '434554158620868609',
								type_value_: '4%股份',
								project_status: '优选发布',
								need_detail_: '桌子',
								project_name_: '汇源果汁',
								user_id_: '434443977751527425',
								need_type_: '人才',
								picture_: 'image2',
								project_desc_: '真好喝'
							},
							{
								project_type_: '科技业',
								user_phone_: '222',
								project_id_: '434559619204907009',
								user_name_: '用户3',
								detail_value_: '100',
								id_: '434559619204907009',
								type_value_: '10%股份',
								project_status: '优选发布',
								need_detail_: '电脑',
								project_name_: '华为项目',
								user_id_: '434443977751527426',
								need_type_: '人才',
								picture_: 'image3',
								project_desc_: '项目简介项目简介'
							},
							{
								project_type_: '教育业',
								user_phone_: '123',
								project_id_: '434559717528043521',
								user_name_: '用户4',
								detail_value_: '100',
								id_: '434559717528043521',
								type_value_: '7%股份',
								project_status: '成交',
								need_detail_: '打印机',
								project_name_: '作业帮2',
								user_id_: '434444372742504449',
								need_type_: '人才',
								picture_: 'image4',
								project_desc_: '项目简介项目简介'
							},
							{
								project_type_: '食品业',
								user_phone_: '123',
								project_id_: '434559825713037313',
								user_name_: '用户1',
								detail_value_: '200',
								id_: '434559825713037313',
								type_value_: '8%股份',
								project_status: '成交',
								need_detail_: '桌子',
								project_name_: '汇源果汁2',
								user_id_: '434443664980705281',
								project_paper_: '',
								need_type_: '人才',
								picture_: 'image5',
								project_desc_: '项目简介项目简介'
							},
							{
								project_type_: '食品业',
								user_phone_: '123',
								user_id_: '434444372742504449',
								user_name_: '用户4',
								id_: '434559825713037314',
								project_status: '成交',
								picture_: 'image4',
								project_desc_: '项目简介',
								project_name_: '汇源果汁3'
							},
							{
								id_: '434559825713037315',
								project_name_: '汇源果汁4'
							}
						]
					},
					isOk: true
				},
				firstImage: {
					code: '200',
					data: {
						count: 3,
						list: [
							{
								pic_: '[{"id":"434549814405103617","name":"WechatIMG124.jpeg"}]',
								status_: '启用',
								id_: '434549818926039041',
								url_: 'http://www.baidu.com',
								name_: '第一张图'
							},
							{
								status_: '2',
								id_: '435028127613452289',
								url_: 'http://www.baidu.com',
								name_: '叶阳茂'
							},
							{
								status_: '1',
								id_: '435028132000956417',
								url_: 'http://www.baidu.com22',
								name_: '第三张图'
							}
						]
					},
					isOk: true
				},
				search: '',
				dropdowns0: '',
				dropdowns1: '',
				dropdowns2: '',
				dropdownsDatas0: [
					{ text: '评论最多', value: 1 },
					{ text: '评论最少', value: 2 }
				],
				dropdownsDatas1: [{ text: '', value: 0 }],
				dropdownsDatas2: [{ text: '距离最近', value: 0 }]
			};
		},
		onShow() {
			this.setCurrentPage(this);
		},
		onLoad(option) {
			this.setCurrentPage(this);
			if (option) {
				this.setData({
					globalOption: this.getOption(option)
				});
			}

			this.init();
		},
		methods: {
			async init() {
				await this.projectApi();
				await this.firstImageApi();
			},
			// 项目列表接口 API请求方法
			async projectApi() {
				let project = await this.$http.post(
					'https://agent.diygw.com/',
					{
						url: '/form/formCustSql/view/liststr_projectList',
						method: 'post',
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						param: '{"curPage":1,"pageSize":"10","params":{}}'
					},
					{
						'Content-type': 'application/json'
					},
					'json'
				);
				this.project = project;
			},
			// 首页轮播图 API请求方法
			async firstImageApi() {
				let firstImage = await this.$http.post(
					'https://agent.diygw.com/',
					{
						url: '/form/formCustSql/view/liststr_imageList',
						method: 'post',
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						param: '{"curPage":1,"pageSize":"10","params":{}}'
					},
					{
						'Content-type': 'application/json'
					},
					'json'
				);
				this.firstImage = firstImage;
			},

			// firstImage 自定义方法
			async firstImageFunction(param) {
				let thiz = this;
				await this.project1Api();

				if (!this.$session.getToken()) {
					//比如未登录，转身到其他页面等
					this.showToast('请先登录');
					return;
				}
			},
			changeDropdowns0(evt) {
				this.setData({ dropdowns0: evt.detail });
				let item = this.dropdownsDatas0.find((item) => {
					return item.value == evt.detail;
				});
				item && item.action && this.navigateTo(item.action);
			},
			changeDropdowns1(evt) {
				this.setData({ dropdowns1: evt.detail });
				let item = this.dropdownsDatas1.find((item) => {
					return item.value == evt.detail;
				});
				item && item.action && this.navigateTo(item.action);
			},
			changeDropdowns2(evt) {
				this.setData({ dropdowns2: evt.detail });
				let item = this.dropdownsDatas2.find((item) => {
					return item.value == evt.detail;
				});
				item && item.action && this.navigateTo(item.action);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.dropdowns-clz {
		flex: 1;
	}
	.text1-clz {
		margin-left: 0px;
		margin-top: 15px;
		margin-bottom: 5px;
		margin-right: 0px;
	}
	.avatar1-clz {
		margin-top: 10px;
		margin-bottom: 5px;
		margin-right: 5px;
	}
	.flex8-clz {
		margin-left: 15px;
		width: calc(100% - 15px - 5px) !important;
		margin-top: 5px;
		margin-bottom: 5px;
		margin-right: 5px;
	}
	.text2-clz {
		font-weight: bold;
	}
	.text6-clz {
		font-weight: bold;
	}
	.text12-clz {
		font-weight: bold;
	}
	.avatar4-clz {
		margin-left: 5px;
		background-size: 100% 100%;
		margin-top: 15px;
		margin-bottom: 5px;
		margin-right: 0px;
	}
	.text21-clz {
		margin-left: 5px;
		margin-top: 5px;
		margin-bottom: 10px;
		margin-right: 5px;
	}
	.container {
		padding-left: 0px;
		padding-right: 0px;

		font-size: 12px;
	}
	.container {
		padding-bottom: 80px;
	}
</style>
